<?php
namespace Admin\Controller;
class SandTableController extends CommonController{
    public function _initialize() {
		parent::_initialize();
        $this->_mod = D('SandTable');
    }

    public function _before_index() {
        //$this->list_relation = true;
        $p = I('p',1,'intval');
        $this->_data = array(
            'addhuxin'    => array(
                'c' => 'Huxin',
                'a' => 'add',
                'str'    => '<a href="%s">添加户型</a>',
                'param' => array('id'=>'@id@','menuid'=>218,'model'=>strtolower(CONTROLLER_NAME)),
                'isajax' => 0,
                'replace'=> ''
            ),
            'huxinindex'    => array(
                'c' => 'Huxin',
                'a' => 'index',
                'str'    => '<a href="%s">户型管理</a>',
                'param' => array('id'=>'@id@','menuid'=>218,'model'=>strtolower(CONTROLLER_NAME)),
                'isajax' => 0,
                'replace'=> ''
            )
        );
        $this->assign('p',$p);
    }

    protected function _search() {
        $map = array();
        ($time_start = I('get.time_start')) && $map['add_time'][] = array('egt', strtotime($time_start));
        ($time_end = I('get.time_end')) && $map['add_time'][] = array('elt', strtotime($time_end)+(24*60*60-1));
        ($keyword = I('get.keyword')) && $map['title'] = array('like', '%'.$keyword.'%');
        $area_id = I('get.area_id',0,'int');
        $site_id = I('get.site_id',0,'int');
		if( $_GET['status']==null ){
            $status = -1;
        }else{
            $status = intval($_GET['status']);
        }
        $status>=0 && $map['status'] = array('eq',$status);
        $selected_ids = '';
        if ($area_id) {
            $id_arr = $this->_cate_mod->get_child_ids($area_id, true);
            $map['area_id'] = array('IN', $id_arr);
            $spid = $this->_cate_mod->where(array('id'=>$area_id))->getField('spid');
            $selected_ids = $spid ? $spid . $area_id : $area_id;
        }
        if($site_id){
            $map['site_id'] = array('eq',$site_id);
        }
        $this->assign('search', array(
            'time_start' => $time_start,
            'time_end' => $time_end,
            'area_id' => $area_id,
            'selected_ids' => $selected_ids,
            'status'  => $status,
            'keyword' => $keyword,
            'site_id' => $site_id
        ));
        return $map;
    }

}